package com.xw.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * servlet生命周期：
 * 			1：从第一次调用到服务器关闭
 * 			2:如果在web.xml里面配置了load-on-startup=1 则是从服务器启动到服务器关闭
 * @author Administrator
 *
 */
public class ServletLife extends HttpServlet {
	
	/**
	 * servlet初始化方法，在servlet第一次被加载到内存的时候被调用
	 * @throws ServletException
	 */
	@Override
	public void init() throws ServletException {
		System.out.println(" 我被加载了！！！！！！！！");
	}

	/**
	 * 真正处理请求的方法
	 * @param req
	 * @param resp
	 * @throws ServletException
	 * @throws IOException
	 */
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.getWriter().write("servlet life");
		System.out.println("servlet life");

	}
	
	@Override
	public void destroy() {
		System.out.println("我被销毁了！！");
	}

}
